🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / settings / src / androidMain / kotlin / org / meshtastic / feature / settings / debugging / LogExporter.kt
Displaying Raw • Download
feature/settings/src/androidMain/kotlin/org/meshtastic/feature/settings/debugging/LogExporter.kt 97ec245a70ef792e54a9e21a2d79c4832ced1d25 (97ec245a) Text, 3.18 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.settings.debugging
Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787android.net.Uri
Tff7b72import T7ee787androidx.activity.compose.rememberLauncherForActivityResult
Tff7b72import T7ee787androidx.activity.result.contract.ActivityResultContracts
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.rememberCoroutineScope
Tff7b72import T7ee787androidx.compose.ui.platform.LocalContext
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.Dispatchers
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787kotlinx.coroutines.withContext
Tff7b72import T7ee787org.meshtastic.core.common.util.ioDispatcher
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.debug_export_failed
Tff7b72import T7ee787org.meshtastic.core.resources.debug_export_success
Tff7b72import T7ee787org.meshtastic.core.ui.util.showToast
Tff7b72import T7ee787java.io.OutputStreamWriter
Tff7b72import T7ee787java.nio.charset.StandardCharsets
Tf0883e@Composable
Tff7b72actual Tff7b72fun Td2a8ffrememberLogExporterTb4b4b4(Te6edf3logsProviderTb4b4b4: Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3ListTff7b72<Te6edf3DebugViewModelTb4b4b4.Te6edf3UiMeshLogTff7b72>Tb4b4b4)Tb4b4b4: Tb4b4b4(Te6edf3fileNameTb4b4b4: Tffa657StringTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tb4b4b4{
Tff7b72val Te6edf3context Tff7b72= Te6edf3LocalContextTb4b4b4.Te6edf3current
Tff7b72val Te6edf3scope Tff7b72= Te6edf3rememberCoroutineScopeTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3exportLogsLauncher Tff7b72=
Te6edf3rememberLauncherForActivityResultTb4b4b4(Te6edf3ActivityResultContractsTb4b4b4.Te6edf3CreateDocumentTb4b4b4(Ta5d6ff"Ta5d6fftext/plainTa5d6ff"Tb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3createdUri Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3createdUri Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{ Te6edf3exportAllLogsToUriTb4b4b4(Te6edf3contextTb4b4b4, Te6edf3createdUriTb4b4b4, Te6edf3logsProviderTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tff7b72return Tb4b4b4{ Te6edf3fileName Tff7b72-Tff7b72> Te6edf3exportLogsLauncherTb4b4b4.Te6edf3launchTb4b4b4(Te6edf3fileNameTb4b4b4) Tb4b4b4}
Tb4b4b4}
Tff7b72private Tff7b72suspend Tff7b72fun Td2a8ffexportAllLogsToUriTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4, Te6edf3targetUriTb4b4b4: Te6edf3UriTb4b4b4, Te6edf3logsTb4b4b4: Te6edf3ListTff7b72<Te6edf3DebugViewModelTb4b4b4.Te6edf3UiMeshLogTff7b72>Tb4b4b4) Tff7b72=
Te6edf3withContextTb4b4b4(Te6edf3ioDispatcherTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3logsTb4b4b4.Te6edf3isEmptyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3withContextTb4b4b4(Te6edf3DispatchersTb4b4b4.Te6edf3MainTb4b4b4) Tb4b4b4{ Te6edf3contextTb4b4b4.Te6edf3showToastTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3debug_export_failedTb4b4b4, Ta5d6ff"Ta5d6ffNo logs to exportTa5d6ff"Tb4b4b4) Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffMeshLog export aborted: no logs availableTa5d6ff" Tb4b4b4}
Tff7b72returnTf0883e@withContext
Tb4b4b4}
Te6edf3contextTb4b4b4.Te6edf3contentResolverTb4b4b4.Te6edf3openOutputStreamTb4b4b4(Te6edf3targetUriTb4b4b4)Tff7b72?.Te6edf3use Tb4b4b4{ Te6edf3os Tff7b72-Tff7b72>
Te6edf3OutputStreamWriterTb4b4b4(Te6edf3osTb4b4b4, Te6edf3StandardCharsetsTb4b4b4.Te6edf3UTF_8Tb4b4b4)Tb4b4b4.Te6edf3use Tb4b4b4{ Te6edf3writer Tff7b72-Tff7b72> Te6edf3formatLogsToTb4b4b4(Te6edf3writerTb4b4b4, Te6edf3logsTb4b4b4) Tb4b4b4}
Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffMeshLog exported successfully to Tffd700$Te6edf3targetUriTa5d6ff" Tb4b4b4}
Te6edf3withContextTb4b4b4(Te6edf3DispatchersTb4b4b4.Te6edf3MainTb4b4b4) Tb4b4b4{ Te6edf3contextTb4b4b4.Te6edf3showToastTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3debug_export_successTb4b4b4, Te6edf3logsTb4b4b4.Te6edf3sizeTb4b4b4) Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3javaTb4b4b4.Te6edf3ioTb4b4b4.Te6edf3IOExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to export logs to URI: Tffd700$Te6edf3targetUriTa5d6ff" Tb4b4b4}
Te6edf3withContextTb4b4b4(Te6edf3DispatchersTb4b4b4.Te6edf3MainTb4b4b4) Tb4b4b4{ Te6edf3contextTb4b4b4.Te6edf3showToastTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3debug_export_failedTb4b4b4, Te6edf3eTb4b4b4.Te6edf3message Tff7b72?: Ta5d6ff"Ta5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s